#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
    vector<int> P = { 7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2 };
    vector<char> M = { '1','0','X','9','8','7','6','5','4','3','2' };
    string tmp;
    vector<string> idcard;
    int n = 0, flag = 0;
    cin >> n;
    for (int i = 0;i < n;i++)
    {
        cin >> tmp;
        idcard.push_back(tmp);
    }
    for (int j = 0;j < idcard.size();j++)
    {
        long long sum = 0;
        tmp = idcard[j];
        for (int i = 0;i < tmp.size();i++)
        {
            if (i == tmp.size() - 1)
            {
                sum %= 11;
                if (M[sum] - '0' != tmp[i] - '0')
                {
                    flag++;
                    cout << tmp << endl;
                    break;
                }
            }
            if (isdigit(tmp[i] - '0') == 0 && i <= tmp.size()-2)
            {
                sum += P[i] * (tmp[i] - '0');
            }
            else if ((isdigit(tmp[i] - '0') != 0) && i <= tmp.size() - 2)
            {
                flag++;
                cout << tmp << endl;
                break;
            }
        }

    }
    if (flag == 0)
    {
        cout << "All passed" << endl;
    }
    return 0;
}
